import requests
import sqlite3
from lxml import etree
from itertools import repeat

for i in range(1, 10):
    num = [i]
    response = requests.get(f"https://www.xiaoshuopu.com/class_{i}/")
    content = response.text
    tree = etree.HTML(content)
    result = tree.cssselect("table tr a[target],table tr .C,.R")
    result_datas = [au.text for au in result]
    tuples = [tuple(result_datas[i:i + 6] + num) for i in range(0, len(result_datas), 6)]
    print(tuples)


    con = sqlite3.connect("../mysite/db.sqlite3")
    cur = con.cursor()
    cur.executemany(f'insert into main_categorypagelist (name,latest_chapter,author,number,last_update_simple,status,category) values (?,?,?,?,?,?,?)', tuples)
    con.commit()
    cur.close()
    con.close()
